/*
 * @Descripttion: 限制elementUI message多条消息提示共存的问题，页面中始终只会存在一个消息提示
 * @Author: 
 * @Date: 2022-06-30 17:37:51
 */

import { ElMessage } from 'element-plus'

let messageInstance = null

export const resetMessage = (options) => {
    if (messageInstance) {
        messageInstance.close()
    }
    // Message 距离窗口顶部的偏移量
    options.offset = 20

    messageInstance = ElMessage(options)
};
['error', 'success', 'info', 'warning'].forEach((type) => {
    resetMessage[type] = (options) => {
        if (typeof options === 'string') {
            options = {
                message: options,
            }
        }
        options.type = type
        return resetMessage(options)
    }
})